<?php
$adminEdit = "";
$obj = "\$object_$class";

$adminEdit .="<?php".$CR."include(\"../../config/config.php\");".$CR;
$adminEdit .="\$identifier = array_key_exists(\"id\",\$_GET)?\$_GET[\"id\"]:\"\";".$CR;

$pk="";

for ($i=0;$i<count($var);$i++){
	
	if ($var[$i]["PK"]!="PRIMARY_KEY"){
		$adminEdit .="$".$var[$i]["name"]." = \"\";".$CR;
	}else{
		$adminEdit .="$".$var[$i]["name"]." = \"\$identifier\";".$CR;
		$pk = $var[$i]["name"];
	}
}

$adminEdit .="".$CR;
$adminEdit .="if (\$identifier != \"\"){".$CR;
$adminEdit .="	// EDIT ITEM".$CR;
$adminEdit .="	\$action = \"EDITAR\";".$CR;
$adminEdit .="".$CR;
$adminEdit .="	\$DM->loadClass(\"$package\",\"$class\");".$CR;
$adminEdit .="	".$obj." = new $class();".$CR;
$adminEdit .="	".$obj."->$pk = \$identifier;".$CR;
$adminEdit .="	".$obj."->getById();".$CR;

for ($i=0;$i<count($var);$i++){
	
	if ($var[$i]["PK"]!="pk"){
		$adminEdit .="	$".$var[$i]["name"]." = ".$obj."->".$var[$i]["name"].";".$CR;
	}
}

$adminEdit .="".$CR;
$adminEdit .="}".$CR;
$adminEdit .="?>".$CR;
$adminEdit .= <<<HEADER_PART_WILL_GO_HERE
<html>
<HEAD>
	<link href="<?php echo HTTP_BASE?>/resource/includes/css/admin.css" type="text/css" rel="stylesheet" rev="stylesheet" />
	<script src="<?php echo HTTP_BASE?>/resource/includes/javascript/jquery/jquery-1.2.3.js"></script>
	<script>
		function checkFilled(){
			mySubmit();
		}
		function comboFix(comboName,value){
			var k = document.cont;
			var cm = k[comboName];
			for (var i=0;i<cm.length;i++){
				if (cm[i].value==value){
					cm.selectedIndex=i;
				}
			}
		}
	</script>
</HEAD>
<body bgcolor='#FFFFFF' onload="">
HEADER_PART_WILL_GO_HERE;
$adminEdit .= "	<form action=\"$class.process.php\" method=\"POST\" enctype=\"multipart/form-data\" name=\"cont\">".$CR;
$adminEdit .= "	<table width='100%' cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#efefef\">".$CR;
$adminEdit .= "		<tr>".$CR;
$adminEdit .= "			<td class='titleTd' bgcolor='#ffffff' width=\"25\">".strtoupper($class)."</td>".$CR;
$adminEdit .= "			<td class='titleTd' bgcolor='#ffffff'><font style='font-wheight:bolder;font-size:11px;'><?php echo \$action?></font>".$CR;
$adminEdit .= "				<input type=\"hidden\" name=\"$pk\" value=\"<?php echo \$$pk?>\">".$CR;
$adminEdit .= "			</td>".$CR;
$adminEdit .= "		</tr>".$CR;
$adminEdit .= "		<tr>".$CR;
$adminEdit .= "			<td colspan=\"2\" class='titleTd' bgcolor='#ffffff'>FORM</td>".$CR;
$adminEdit .= "		</tr>".$CR;
$adminEdit .= "		<tr>".$CR;
$adminEdit .= "			<td colspan=\"2\" height=\"20\">&nbsp;</td>".$CR;
$adminEdit .= "		</tr>".$CR;

$line="line1";
for ($i=0;$i<count($var);$i++){
	
	if ($var[$i]["PK"]!="pk"){
		
		if ($var[$i]["name"]!="updated_on" && $var[$i]["name"]!="created_on"){
			$adminEdit .= "		<tr>".$CR;
			$adminEdit .= "			<td class='$line'>".$var[$i]["title"]."</td>".$CR;
			switch ($var[$i]["type"]){
				case "TEXT":
					$adminEdit .= "			<td class='$line'><textarea class='inputClass' rows='4' cols='60' name=\"".$var[$i]["name"]."\"><?php echo \$".$var[$i]["name"]."?></textarea></td>".$CR;
					break;
				case "ENUM":
					$myEnum = explode(',',$var[$i]["default"]);
					$enmOpt = "";
					for ($w=0;$w<count($myEnum);$w++){
						$enmOpt .="\n\t\t<option value=".$myEnum[$w].">".ltrim(rtrim($myEnum[$w],"'"),"'")."</option>"; 
					}
					$adminEdit .= "			<td class='$line'><select class='inputClass' name=\"".$var[$i]["name"]."\">$enmOpt</select></td>".$CR;				
					$adminEdit .= "			<script>comboFix(\"".$var[$i]["name"]."\",'<?php echo \$".$var[$i]["name"]."?>');</script>".$CR;				
					break;
				case "ONOFF":
					$adminEdit .= "			<td class='$line'>
					<input type=\"radio\" class='inputClass' name=\"".$var[$i]["name"]."\" value=\"0\" <?php echo (\$".$var[$i]["name"]."==0?\"checked\":\"\")?>> OFF / 
					<input type=\"radio\" class='inputClass' name=\"".$var[$i]["name"]."\" value=\"1\" <?php echo (\$".$var[$i]["name"]."==1?\"checked\":\"\")?>> ON</td>".$CR;
					break;
				default:
					$inptmax = "";
					$inptSize = " size=\"10\"";
					if ($var[$i]["length"]!=""){
						$inptmax = " MAXLENGTH=\"".$var[$i]["length"]."\"";
						
						$inptSize = " style=\"width:".($var[$i]["length"]*3)."px;\"";
					}
					$adminEdit .= "			<td class='$line'><input type=\"text\" $inptmax $inptSize class='inputClass' name=\"".$var[$i]["name"]."\" value=\"<?php echo \$".$var[$i]["name"]."?>\"></td>".$CR;
				break;
			}
			$adminEdit .= "		</tr>".$CR;
		}
	}
	$line = $line=="line1"?"line2":"line1";
		
}

$adminEdit .=<<<THIS_IS_THE_END
		<tr>
			<td colspan="2" class="$line" align='right'><input type="button" value="CANCELAR" class='minorAction' onclick="history.go(-1);">&nbsp;<input type="button" value="SALVAR" class='minorAction' onclick="checkFilled();"></td>
		</tr>
	</table>
</form>
<script type="text/javascript">
	function mySubmit() {
		document.cont.submit();
	};
</script>
</body>
</html>
THIS_IS_THE_END;

//print_r(htmlentities($adminEdit));

?>

